import { defineStore } from 'pinia'

export const useUserState  = defineStore('user', {
    state: () => {
        return {
            // 获取本地状态
            userinfo: null,
            error: null,
            count: 0
        }
    },

    getters: {
        doubleCount(state) {
            return this.userinfo = state
        },
    },


    actions: {
        async restoreFromLocalStorage() {
            const routers = useRouter()
            try {
                const storedUser = localStorage.getItem('star-bucket-info')
                if (storedUser) {
                    this.userinfo = JSON.parse(storedUser);
                }
            } catch (error) {
                // 处理获取 localStorage 失败的情况
                this.error = error.message;
            }
        }
    }
})